"""
Here are the possible outcomes:
I hunt + They hunt = (6 + 6)/2 - 6 = 0
I slack + They hunt = (0 + 6)/2 - 2 = 1
I hunt + They slack = (6 + 0)/2 - 6 = -3
I slack + They slack = (0 + 0)/2 - 2 = -2

Best case scenario is I slack and They hunt
We both hunt breaks even
Worst case is I hunt and They slack
Better but still bad is we both slack

So... What shall my strategy be? Hmm...

Reputation is the fraction of rounds that They have hunted.
I will play based only on reputation. If I get some extra food because of m that's just a bonus.

I have probability P to hunt. They have probability Q to hunt (their reputation). So:
I hunt + They hunt for outcome 0 has probability P and Q = PQ
I slack + They hunt for outcome 1 has probability not P and Q = (1-P)Q
I hunt + They slack for outcome -3 has probability P and not Q = P(1-Q)
I slack + They slack for outcome -2 has probability not P and not Q = (1-P)(1-Q)

Okay, let's weight each outcome with its probability and sum: 0*PQ + 1*(1-P)Q - 3*P(1-Q) - 2*(1-P)(1-Q)
Simplified: 3Q - P - 2 = average outcome given Q and P
We can control P but we are given Q. We need to maximize the average outcome.
The best we can do is set P = 0, it does not matter what the other player does.

So the best strategy based only on reputation is to disregard reputation and always slack.

Okay, let's ignore the reputation altogether and see if there isn't a better strategy based on 'm'.
If the total number of hunts in a round is >= m then we all get extra food.
This means that if everyone hunts everyone wins and nobody loses.
If the other player is likely to hunt, we should also hunt. We lose nothing and we might gain something because of 'm'.
If the other player is likely to slack, we should also slack to limit our losses.

Given all this reasoning... let's formulate a likely good strategy.
We should start off with a good reputation, so that other rationally good players will hunt with us too.
So always hunt in the first round to get a perfect reputation of 1.
After that we hunt or slack off depending on the reputation of our partner, but biased towards hunting depending on 'm'.
If our partner is likely to slack, we also slack (I've decided on a reputation threshold of 95% for this based on some experiments)
If m is very low, it's quite likely the round will go over the threshold even if we don't hunt.
If m is very high, it's quite likely the round will not go over the threshold even if we hunt every time.
Therefore only m values in the mid-range should count as a high bias towards hunting.
Use this m-bias to hunt randomly with our partner if their reputation is very high.

"""

import random

def hunt_choices(round_number, current_food, current_reputation, m, player_reputations):
	hunt_decisions = list()
	
	# First round: always hunt
	if round_number == 1:
		for r in player_reputations:
			hunt_decisions.append('h')
		return hunt_decisions

	# Calculate a ratio based on m and total number of players this around
	# Get the threshold by transforming the ratio values such that 0.5 yields 1.0 but values of 0.0 or 1.0 yield 0.0
	num_players = float(len(player_reputations)) + 1.0
	mratio = float(m) / (num_players * (num_players - 1.0))
	mthreshold = 1.0 - abs(mratio-0.5)*2.0
	
	# If the player's reputation is anything less than 95%, then always slack
	# Otherwise slack or hunt randomly based off of the mthreshold for this round
	for r in player_reputations:
		if r < 0.95:
			choice = 's'
		else:
			choice = 'h' if random.random() < mthreshold else 's'
		hunt_decisions.append(choice)
	return hunt_decisions

def hunt_outcomes(food_earnings):
	pass # do nothing

def round_end(award, m, number_hunters):
	pass # do nothing
